package me.ljd.yigo.utils;

import java.util.Arrays;

import com.bokesoft.yes.common.util.StringUtil;
import com.bokesoft.yigo.mid.base.DefaultContext;
import com.bokesoft.yigo.mid.connection.IDBManager;
import com.bokesoft.yigo.struct.datatable.DataTable;


public class HandleDBQuery2 {
	public static Object handle(DefaultContext context, Object[] args) throws Throwable {
		DataTable dataTable = DBManagerUtil2.getTableNew(context);
		if(args.length<1 || StringUtil.isBlankOrNull(args[0])) {return dataTable;}
		String sql = (String)args[0];
		try {
			IDBManager dbManager=DBManagerUtil2.getDBManager(1);
			dataTable = dbManager.execPrepareQuery(sql, Arrays.copyOfRange(args, 1,args.length));
			//dbManager.close();
			dataTable.batchUpdate();
		} catch (Throwable e) {
			System.out.println(sql);
			e.printStackTrace();
			throw new IllegalArgumentException("数据查询出错");
		}
		return dataTable;
	}
}
